package cn.com.cetccst.network;


import cn.com.cetccst.network.log.RetrofitLogger;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class BaseCallback<T> implements Callback<T> {

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        if (response != null) {
            RetrofitLogger.info("response:" + response.toString());
            //TODO 增加一个
        }
        onResponse(response.body());
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        RetrofitLogger.error(call.request().toString(), t);
        if (call.isCanceled()) {
            return;
        }
        //此时调用正常返回，传递null
        onResponse( null);
    }


    public abstract void onResponse(T data);
}
